package com.klhappy.houyuan.modle;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.klhappy.houyuan.bean.AddressBean.AddressBean;
import com.klhappy.houyuan.bean.ExtractMoneyBean.AccBean;
import com.klhappy.houyuan.bean.FamilyInt;
import com.klhappy.houyuan.bean.FeedBackBean;
import com.klhappy.houyuan.constant.KeyConstant;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.utils.BaseModel;
import com.klhappy.houyuan.utils.ConfigManager;
import com.klhappy.houyuan.utils.okhttp.BaseBeanCallback;
import com.klhappy.houyuan.utils.okhttp.ImgBean;
import com.klhappy.houyuan.utils.okhttp.OkHttpUtils;
import com.squareup.okhttp.Request;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by MrPu on 15/11/25.
 */
public class JiaYuanModle extends BaseModel {

    private Map<String, String> params = new HashMap<>();

    private ConfigManager manage;

    private String cookie;

    private Context context;

    public JiaYuanModle(Context context) {
        super(context);
        this.context = context;
        manage = new ConfigManager(context);
        cookie = manage.get(KeyConstant.session, cookie);
    }

    //登录请求
    public void getLogin(){
        String path = UrlConstant.LOGIN_URL;

        params.put("own_mob_no", manage.get(KeyConstant.account, ""));
        params.put("own_pwd", manage.get(KeyConstant.password, ""));
        params.put("plat_type", "1");
        Callback(path ,params);
    }

    //我的家园
    public void getJiaYuan(Context context) {
        String path = UrlConstant.HOMEINFOR_URL;
        cookie = manage.get(KeyConstant.session, cookie);
        Callback(path, params, cookie);
    }

    //家庭成员
    public void getFamily() {
        String path = UrlConstant.MEMBER_URL;

        Callback(path, params, cookie);
    }

    //获取收货地址
    public void getAddress() {
        String path = UrlConstant.ADRESS_URL;

        Callback(path, params, cookie);
    }

    //生成收货地址
    public void setAddress(String name, String phone, String loction, String number) {
        String path = UrlConstant.ADDADRESS_URL;

        params.put("action", 1 + "");
        params.put("name", name);
        params.put("phone", phone);
        params.put("address", loction + number);
        Callback(path, params, cookie);
    }

    //粮票规则
    public void getResult() {
        String path = UrlConstant.FOODRULE_URL;

        Callback(path, params);
    }

    //获取可使用的粮票
    public void getFoods() {
        String path = UrlConstant.TICKETS_URL;

        Callback(path, params, cookie);
    }
    //获取粮票
    public void getStamp(){
        String path = UrlConstant.STAMP_URL;

        Callback(path ,params ,cookie);
    }
    //删除地址
    public void RemoveAddress(String id){
        String path = UrlConstant.REMOVEADDRESS_URL;

        params.put("id" , id);
        Callback(path ,params ,cookie);
    }
    //修改昵称
    public void setName(String name){
        String path = UrlConstant.ACCOUNT_URL;

        params.put("nickname" ,name);
        params.put("action" ,"3");
        Callback(path, params, cookie);
    }
    //业绩显示
    public void getYeJi(){
        String path = UrlConstant.CONSUME_URL;

        Callback(path ,params ,cookie);
    }
    //删除家人
    public void RemoveFamily(String own_id){
        String path = UrlConstant.REFAMILY_URL;

        params.put("own_id" ,own_id);
        Callback(path ,params ,cookie);
    }
    //获取提现验证码
    public void getTixian(){
        String path = UrlConstant.GET_REGIST_URL;

        params.put("phone" ,manage.get(KeyConstant.account, ""));
        Callback(path ,params ,cookie);
    }
    //提现申请
    public void setTixian(AccBean accBean){
        String path = UrlConstant.SETACCOUNT_URL;
        Log.e("this" ,cookie);
        params.put("accname" ,accBean.getAccname());
        params.put("Account" ,accBean.getAccount());
        params.put("money" ,accBean.getMoney());
        params.put("pwd" ,accBean.getPwd());
        params.put("vercode" ,accBean.getVercode());
        params.put("acctype" ,accBean.getAcctype());
        Callback(path ,params ,cookie);
    }
    //保存默认地址
    public void setNewAddress(AddressBean.Records records){
        String path = UrlConstant.ACCOUNT_URL;

        params.put("action", "2");
        params.put("id", records.getId() + "");
        params.put("address", records.getAddress() + "");
        params.put("name", records.getUser_name() + "");
        params.put("phone", records.getOwn_mob_no() + "");
        params.put("is_default_addr", "1");
        Callback(path ,params ,cookie);
    }
    //获取默认地址
    public void getDeAddress(){
        String path = UrlConstant.DEADDRESS_URL;

        Callback(path ,params ,cookie);
    }
}
